package com.test.exam.service;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.test.exam.commons.PageHelper;
import com.test.exam.dao.BanDao;
import com.test.exam.domain.Ban;

@Service
public class BanService {
	private final int BAN_ROW_PER_PAGE = 3; 
	
	@Autowired
	private BanDao banDao;
		
	// end page
	public int getEndPage(){
		int count = banDao.getBanCount();
		if(count == 0){
			return 0;
		}
		return (int)(Math.ceil((float)count/(float)BAN_ROW_PER_PAGE));
	}
	// 페이지 반 목록
	public List<HashMap> getBansByCurrentPage(int currentPage){
		PageHelper pageHelper = new PageHelper();
		pageHelper.setRowPerPage(BAN_ROW_PER_PAGE);
		pageHelper.setStartRow(currentPage);
		return banDao.getBansByCurrentPage(pageHelper);
	}
	
	public List<HashMap> getAllBans(){
		return banDao.getAllBans();
	}
	
	public int addBan(Ban ban){
		return banDao.addBan(ban);
	}
}
